package com.efuture.servlet.request;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;

/**
 * @description: 通过Request获取请求行数据
 * @author zhaoshanshan
 * @date 2021/10/2 10:11 下午
 * @version 1.0
 */

@WebServlet("/GetRequestLine")
public class GetRequestLine extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        1. 获取请求方式 ：GET
//                * String getMethod()
        String method = request.getMethod();
        System.out.println(method);
//        2. (*)获取虚拟目录：
//                * String getContextPath()
        String contextPath = request.getContextPath();
        System.out.println(contextPath);
//        3. 获取Servlet路径: /GetRequestLine
//                * String getServletPath()
        String servletPath = request.getServletPath();
        System.out.println(servletPath);
//        4. 获取get方式请求参数：name=zhangsan
//                * String getQueryString()
        String requestStr = request.getQueryString();
        System.out.println(requestStr);
//        5. (*)获取请求URI：/GetRequestLine
//                * String getRequestURI():		/GetRequestLine
//                * StringBuffer getRequestURL()  http://localhost:8080/GetRequestLine
//
//				* URL:统一资源定位符 ： http://localhost/day14/demo1	中华人民共和国
//				* URI：统一资源标识符 : /day14/demo1					共和国
        String requestURI = request.getRequestURI();
        System.out.println(requestURI);
        StringBuffer requestURL = request.getRequestURL();
        System.out.println(requestURL);
//
//        6. 获取协议及版本：HTTP/1.1
//                * String getProtocol()

        String protocol = request.getProtocol();
        System.out.println(protocol);
//
//        7. 获取客户机的IP地址：
//				* String getRemoteAddr()
       String remoteAddr = request.getRemoteAddr();
       System.out.println(remoteAddr);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
